package cn.ekuma.pos.pda.sale;

import cn.ekuma.android.keyBoardinput.KeyBoradInputPanel;
import cn.ekuma.android.ui.scan.CaptureScanActivity;
import cn.ekuma.epos.android.finder.AdvProductSelectActivate;
import cn.ekuma.epos.android.finder.CustomerFinderActivate;
import cn.ekuma.epos.bean.util.sale.TicketHelper;
import cn.ekuma.pos.android.pos.R;
import cn.ekuma.pos.pda.finder.ShardTicketFinder;

import android.content.Intent;
import android.os.Bundle;

import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;


public class TicketSaleActivity extends AbstractTicktSaleActivity{
	

	protected ImageButton btnSelectShardTicket,btnSelectTable,btnBarcode,btnSelectProduct,btn_adv_newticket,btn_adv_clearticket;
	protected Button btnTicketTitle,ticket_txt_state;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pos_ticket_edit);
		Bundle mBundle=getIntent().getExtras();
		
		lineAdapter=new TicketLineListAdapter(this);
		ticketList=new TicketLines(this,ticketManager,lineAdapter);
		ViewGroup contentPanel=(ViewGroup) this.findViewById(R.id.content_panel);
		contentPanel.addView(ticketList);
		
		ticket_txt_state=(Button) findViewById(R.id.ticket_txt_state);
		
		btnTicketTitle=(Button) findViewById(R.id.btnTicketTitle);
		btnSelectShardTicket=(ImageButton) findViewById(R.id.btnSelectShardTicket);
		btnSelectTable=(ImageButton) findViewById(R.id.btnSelectTable);
		btnSelectProduct=(ImageButton) findViewById(R.id.btnSelectProduct);
		btnBarcode=(ImageButton) findViewById(R.id.btnBarcode);
		
		btn_adv_newticket=(ImageButton) findViewById(R.id.btn_adv_newticket);
		btn_adv_clearticket=(ImageButton) findViewById(R.id.btn_adv_clearticket);
		
		btnSelectShardTicket.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				Intent intent = new Intent();
		    	intent.setClass(TicketSaleActivity.this, ShardTicketFinder.class);
		    	startActivityForResult(intent,SELECT_TICKET);
			}
		});
		keyInportPanel=(KeyBoradInputPanel) findViewById(R.id.ticket_key_import);

		
		
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
                WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

		btnBarcode.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				Intent intent = new Intent();
		    	intent.setClass(TicketSaleActivity.this, CaptureScanActivity.class);
		    	startActivityForResult(intent,SCAN_PRODUCTS);
			}
		});
		
		
		btnSelectProduct.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				Intent intent = new Intent();
		    	intent.setClass(TicketSaleActivity.this, AdvProductSelectActivate.class);
		    	startActivityForResult(intent,SELECT_PRODUCTS);
			}
		});
		
		btnTicketTitle.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				Intent intent = new Intent();
		    	intent.setClass(TicketSaleActivity.this, CustomerFinderActivate.class);
		    	startActivityForResult(intent,SELECT_CUSTOMER);
			}
		});
		
		ticket_txt_state.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				ticketManager.saveCurrentTicket();
			}
		});
		
		btn_adv_newticket.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				ticketManager.newTicket();
			}
		});
		
		btn_adv_clearticket.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				ticketManager.clearCurrentTicket();
			}
		});
		
		ticketList.setOnBaseBeanSelectedListener(this);
		
		keyInportPanel.setVisibility(View.VISIBLE);
		keyInportPanel.setInputListener(this);
				
		init();
		
		//registerForContextMenu(ticketList.getListview());
		
		
	}

	@Override
	public void refushState() {
		btnTicketTitle.setText(TicketHelper.getName(ticketManager.getCurrentTicket()));
    	ticket_txt_state.setText(TicketHelper.printTotal(ticketManager.getCurrentTicket()));
	}
	
	
	
	
	/**public void onCreateContextMenu(ContextMenu menu, View v,     
             ContextMenuInfo menuInfo) {  
         super.onCreateContextMenu(menu, v, menuInfo);  
         menu.add(0,0,0,"回复评论");  
    }     

	
	
	public boolean onContextItemSelected(MenuItem aItem) {         
        ContextMenuInfo menuInfo = (ContextMenuInfo) aItem.getMenuInfo();   
        Toast ta;  
        ta = Toast.makeText(TicketSaleActivity.this, "onContextItemSelected", Toast.LENGTH_LONG);  
        ta.show();  
        return false;    
	}*/


	
	
}
